package com.hb.znpt.activity;

import android.os.Bundle;

import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.hb.znpt.BR;
import com.hb.znpt.R;
import com.hb.znpt.adapter.LeaseAdapter;
import com.hb.znpt.bean.LeaseBean;
import com.hb.znpt.databinding.ActivityLeaseBinding;
import com.hb.znpt.viewmodel.LeaseViewModel;
import com.unitlib.base.base.BaseActivity;

import java.util.List;

public class LeaseActivity extends BaseActivity<ActivityLeaseBinding, LeaseViewModel> {

    private LeaseAdapter adapter;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_lease;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        initBackTitle(binding.toolbar);
        initRecyclerView();
    }

    @Override
    public void initViewObservable() {
        viewModel.listData.observe(this, new Observer<List<LeaseBean>>() {
            @Override
            public void onChanged(List<LeaseBean> beans) {
                adapter.setList(beans);
            }
        });
    }

    /**
     * Init recycler view.
     * 初始化RecyclerView
     */
    public void initRecyclerView() {
        adapter = new LeaseAdapter();
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        binding.recyclerView.setLayoutManager(layoutManager);
        binding.recyclerView.setAdapter(adapter);
    }
}
